import re
my_dict = ({'LEND_LEASE_DELIVERY_TOTAL_DAYS': '1',
            'VOLUNTEERS_TRANSFER_SPEED': '1', 
            'VOLUNTEERS_DIVISIONS_REQUIRED': '1', 
            'PURCHASE_CONTRACT_DELIVERY_TOTAL_DAYS': '1', 
            'NAVAL_SUPREMACY_CAN_INVADE': '-0.5', 
            'MAX_DISTANCE_NAVAL_INVASION': '20000.0', 
            'ENEMY_NAVY_STRENGTH_DONT_BOTHER': '2000', 
            'NAVAL_INVASION_PREPARE_HOURS': '1', 
            'STRATEGIC_SPEED_INFRA_BASE': '50', 
            'STRATEGIC_SPEED_RAIL_BASE': '150', 
            'NAVAL_TRANSFER_BASE_SPEED': '60', 
            'FRONT_MIN_PATH_TO_REDEPLOY': '6', 
            'STRATEGIC_REDEPLOY_ORG_RATIO': '0.3', 
            'MIN_DIVISION_DEPLOYMENT_TRAINING': '0', 
            'FOCUS_POINT_DAYS': '1', 
            'BASE_TECH_COST': '50', 
            'BASE_FACTORY_SPEED': '500', 
            'BASE_FACTORY_SPEED_MIL': '4.5', 
            'ANNEX_STOCKPILES_RATIO': '0', 
            'ANNEX_FIELD_EQUIPMENT_RATIO': '0',
            'ANNEX_CONVOYS_RATIO': '0',
            'CAPITULATE_STOCKPILES_RATIO': '0',
            'RIVER_CROSSING_PENALTY': '0',
            'RIVER_CROSSING_PENALTY_LARGE': '0',
            'AMPHIBIOUS_LANDING_PENALTY': '0',
            'MARKET_ACCESS_ACCEPTANCE_OPINION': '1000',
            'EQUIPMENT_PURCHASE_ACCEPTANCE_OPINION': '1000',
            'MAX_OPINION_VALUE': '100',
            'MIN_OPINION_VALUE': '10',
            'OPINION_CUTOFF_FOR_IMPROVE_RELATIONS': '-10',
            'DEPLOY_MIN_TRAINING_SURRENDER_FACTOR': '0.01',
            'DEPLOY_MIN_TRAINING_PEACE_FACTOR': '0.01',
            'DEPLOY_MIN_TRAINING_WAR_FACTOR': '0.01',
            'LAND_COMBAT_STR_DAMAGE_MODIFIER': '0.18',
            'LAND_COMBAT_ORG_DAMAGE_MODIFIER': '1',
            # 'MIN_WAR_SUPPORT': '0',
            'BASE_SURRENDER_LIMIT': '0.3',
            'SURRENDER_LIMIT_MULT_FOR_COUNTRIES_WITH_NO_CORES': '0.2',
            'MIN_SURRENDER_LIMIT': '0.3',
            'BASE_MOBILIZATION_SPEED': '1',
            'PRODUCTION_RESOURCE_LACK_PENALTY': '0',
            })

# path
file_path = r'E:\SteamLibrary\steamapps\common\Hearts of Iron IV\common\defines\00_defines.lua'
# file_path = '/home/h/build/game-modify/hoi4/test.lua'

# read file

with open(file_path, 'r', encoding='utf-8') as file:
    content = file.readlines()

for key in my_dict:
    regular_express = key + ' ' + '=' + ' ' + '.*?,'
    target = key + ' ' + '=' + ' ' + my_dict[key] + ','
    # print(regular_express, target)
    content = [re.sub(regular_express, target, line) for line in content]


# write back

with open(file_path, 'w', encoding='utf-8') as file:

    file.writelines(content)